package com.zhao.fishingguideserver.controller;

import com.zhao.fishingguideserver.POJO.Result;
import com.zhao.fishingguideserver.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 数据看板控制器
 */
@RestController
@RequestMapping("/admin/dashboard")
public class DashboardController {
    
    @Autowired
    private DashboardService dashboardService;
    
    /**
     * 获取核心数据统计
     */
    @GetMapping("/summary")
    public Result<Map<String, Object>> getSummary() {
        try {
            Map<String, Object> summary = dashboardService.getSummary();
            return Result.success(summary);
        } catch (Exception e) {
            return Result.error("获取数据统计失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取用户增长趋势
     */
    @GetMapping("/userTrend")
    public Result<List<Map<String, Object>>> getUserTrend() {
        try {
            List<Map<String, Object>> trend = dashboardService.getUserGrowthTrend();
            return Result.success(trend);
        } catch (Exception e) {
            return Result.error("获取用户趋势失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取销售趋势
     */
    @GetMapping("/salesTrend")
    public Result<List<Map<String, Object>>> getSalesTrend() {
        try {
            List<Map<String, Object>> trend = dashboardService.getSalesTrend();
            return Result.success(trend);
        } catch (Exception e) {
            return Result.error("获取销售趋势失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取帖子发布趋势
     */
    @GetMapping("/postTrend")
    public Result<List<Map<String, Object>>> getPostTrend() {
        try {
            List<Map<String, Object>> trend = dashboardService.getPostTrend();
            return Result.success(trend);
        } catch (Exception e) {
            return Result.error("获取帖子趋势失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取热门帖子Top10
     */
    @GetMapping("/hotPosts")
    public Result<List<Map<String, Object>>> getHotPosts() {
        try {
            List<Map<String, Object>> posts = dashboardService.getHotPosts();
            return Result.success(posts);
        } catch (Exception e) {
            return Result.error("获取热门帖子失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取活跃用户Top10
     */
    @GetMapping("/activeUsers")
    public Result<List<Map<String, Object>>> getActiveUsers() {
        try {
            List<Map<String, Object>> users = dashboardService.getActiveUsers();
            return Result.success(users);
        } catch (Exception e) {
            return Result.error("获取活跃用户失败：" + e.getMessage());
        }
    }
}

